#pragma once

#include "../../base/types.h"
#include "../../container/ordered_map.h"

OPEN_JLIB_NS


struct NotificationManager {

  using id_type = u64;
  using data_type = const void*;
  using name_type = std::string;
  using func_type = std::function<void(data_type)>;

  id_type registerListener (const name_type &channel, func_type callback) noexcept;
  bool unregisterListener (const name_type &channel, id_type id) noexcept;
  bool cleanChannel (const name_type &channel) noexcept;
  void cleanAll () noexcept;

  uwl broadcast (const name_type &channel, data_type data = nullptr);

  inline id_type obtainId () noexcept { return _seed++; }

private:
  ordered_map<name_type, ordered_map<id_type, func_type> > _channels;
  id_type _seed = 0;
};


CLOSE_JLIB_NS
